﻿using System;
using ReadyApps.Wiki;

namespace ReadyApps.Data.Wiki
{
    /// <summary>
    /// Used to contain initial information about a wiki page when searching the data
    /// source.
    /// </summary>
    public class PageLookup
    {
        #region Variables

        private static readonly PageLookup pageNotFoundLookup;
        private static readonly PageLookup siteNotFoundLookup;

        #endregion

        #region Properties

        /// <summary>
        /// Gets a value indicating whether or not the requested site was found in the
        /// data source.
        /// </summary>
        public bool SiteFound { get; private set; }

        /// <summary>
        /// Gets a value indicating whether or not the requested page was found in the
        /// data source.
        /// </summary>
        public bool PageFound { get; private set; }

        /// <summary>
        /// Gets the page ID of the requested page if the page was found in the data
        /// source.
        /// </summary>
        public int PageID { get; private set; }

        /// <summary>
        /// Gets the <see cref="PageDetails"/> for the requested page if the page was
        /// found in the data source.
        /// </summary>
        public PageDetails Details { get; private set; }

        /// <summary>
        /// Gets a common <see cref="PageLookup"/> that represents the data returned
        /// when a requested page is not found in the data source.
        /// </summary>
        public static PageLookup PageNotFoundLookup
        {
            get { return pageNotFoundLookup; }
        }

        /// <summary>
        /// Gets a common <see cref="PageLookup"/> that represents the data returned
        /// when a requested site is not found in the data source.
        /// </summary>
        public static PageLookup SiteNotFoundLookup
        {
            get { return siteNotFoundLookup; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Creates the static page not found and site not found data objects.
        /// </summary>
        static PageLookup()
        {
            pageNotFoundLookup = new PageLookup(1, null);
            pageNotFoundLookup.PageID = WikiController.IMPOSSIBLE_PAGE_ID;
            pageNotFoundLookup.PageFound = false;
            siteNotFoundLookup = new PageLookup(1, null);
            siteNotFoundLookup.PageID = WikiController.IMPOSSIBLE_PAGE_ID;
            siteNotFoundLookup.SiteFound = false;
            siteNotFoundLookup.PageFound = false;
        }

        /// <summary>
        /// Creates a new <see cref="PageLookup"/> with the given page ID and
        /// page details.
        /// </summary>
        /// <param name="pageID">The page ID for the requested page.</param>
        /// <param name="details">The detailed information about the page.</param>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="pageID"/>
        /// parameter was less than one.</exception>
        public PageLookup(int pageID, PageDetails details)
        {
            if (pageID < 1)
            {
                throw new ArgumentOutOfRangeException("pageID", "The pageID must be greater than or equal to one");
            }
            //if (details == null)
            //{
            //    throw new ArgumentNullException("details");
            //}
            PageID = pageID;
            Details = details;
            SiteFound = true;
            PageFound = true;
        }

        #endregion
    }
}
